﻿using System;
using System.Collections.Generic;
using System.Text;
using Scripting;

namespace Scripts.RCPKit
{
    public enum GuildRole
    {
        Member  = 0,
        Officer = 1,
        Leader  = 2
    }

    public class GuildMember : ScriptBase
    {
        private ActorInfoRequest Request;

        public string ActorName;
        public string ActorLocation;
        public bool ActorOnline;
        public GuildRole ActorGuildrole = GuildRole.Member;


        public GuildMember(string actorName)
        {
            ActorName = actorName;
            GetActorStatus();
        }

        public GuildMember(string actorName,int ranknumber)
        {
            ActorName = actorName;
            GetActorStatus();
        }
        public GuildMember(string actorName, string actorLocation, bool actorOnline, GuildRole actorGuildRole)
        {
            ActorName = actorName;
            ActorLocation = actorLocation;
            ActorGuildrole = actorGuildRole;
        }

        public void GetActorStatus()
        {
            CheckOnline();
            if (DatabaseSettings.DatabaseProvider == DatabaseType.SQLite)
            {
                
            }
            else if (DatabaseSettings.DatabaseProvider == DatabaseType.MySQL)
            {

            }
        }

        public void CheckOnline()
        {
            // Setup request (search for online only)
            Request = new ActorInfoRequest(ActorName, ActorInfoRequestState.All);
            RegisterCallback(Request, "Complete", new ActorInfoRequest.RequestHandler(Request_Complete));

            // Post request
            RCScript.PostActorInfoRequest(Request);
        }

        /// <summary>
        /// Called when the request is completed
        /// </summary>
        public void Request_Complete(ActorInfo actorInfo)
        {
            RCScript.Log(actorInfo.State.ToString());
            // Always check the state
            if (actorInfo.State == ActorInfoState.Online)
            {
                ActorOnline = true;
            }
            else
            {
                ActorOnline = false;
            }

            // Cleanup
            UnRegisterCallback(Request, "Complete", new ActorInfoRequest.RequestHandler(Request_Complete));
        }

        public static string PlayersGuild(string ActorName)
        {
            if (DatabaseSettings.DatabaseProvider == DatabaseType.SQLite)
            {

            }
            else
            {

            }
            return null;
        }
    }
}
